/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.documents.service;

import com.documents.common.core.PageBean;
import com.documents.common.core.service.BaseSrv;
import com.documents.pojo.Message;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class MessageService extends BaseSrv<Message, Integer> {

    public PageBean getPageBean(int page, int pageSize, Message type) {
        PageBean pageBean = new PageBean();
        pageBean.setPageSize(pageSize);
        pageBean.setCurrentPage(page);
        String condition = "";
        Object[] parameters = new Object[1];
        
        int paramIndex = 0;
        if (type != null) {


            if (type.getState() > 0) {
                if (condition.trim().length() == 0) {
                    condition += "state=?";
                } else {
                    condition += "and state=?";
                }

                parameters[paramIndex] = type.getState();
                paramIndex++;
            }
        }




        Long allRow = this.findTotalCount(condition, parameters);
        int totalPage = PageBean.countTotalPage(pageSize, allRow.intValue()); // 总页数
        pageBean.setAllRow(allRow.intValue());
        pageBean.setTotalPage(totalPage);
        List<Message> list;
        if (page == 1) {
            list = this.findWithPaging(condition, parameters, "state", page - 1, pageSize);
        } else {
            list = this.findWithPaging(condition, parameters, "state", (page - 1) * pageSize, pageSize);
        }

        pageBean.setList(list);

        return pageBean;
    }

    public List<Message> getMessageListTop(int state) {

        List<Message> nlist = this.findWithPaging("state=?", new Object[]{state}, "createtime desc", 0, 5);
        return nlist;
    }
}
